
<%@page import="java.util.HashMap"%>
<%@page import="com.office.automate.configuration.property.ConfigurationProperties"%>
<%@page import="java.util.Properties"%>
<%@page import="com.office.automate.frontier.utility.DataConversionUtility"%>
<%@page import="com.office.automate.exception.framework.FrontierVisibleException"%>
<%@page import="java.util.List"%>
<%@page import="com.office.automate.datagrid.framework.DataGridComponentFramework"%>
<% 
try {
	Properties configProps = ConfigurationProperties.getProps();
	DataConversionUtility dataconversion = new DataConversionUtility();
	DataGridComponentFramework framework = new DataGridComponentFramework();
	String dataGridPageID = (String) request.getParameter("aDataGridPageID");
	List<String> fieldHeadings = framework.getFieldNames(dataGridPageID);
	int dataFieldCoulmnCount = framework.getDataFieldColumnCount(dataGridPageID);
	long employeeId = dataconversion.convertStringToLong(request.getParameter("aCurrentUser"));
	int nextRowNumber = dataconversion.convertStringToNumber(request.getParameter("aNextRowNumber"));
	int numberOfRecordsPerPage = dataconversion.convertStringToNumber(configProps.getProperty("LEAVE_HISTORY_DISPLAY_RECORD_COUNT"));
	String buttonUpdateCaption = (String)request.getParameter("aButtonUpdateCaption");
	String buttonDeleteCaption = (String)request.getParameter("aButtonDeleteCaption");
	String buttonOtherCaption = (String)request.getParameter("aButtonOtherCaption");
	boolean buttonsNextPrevious = dataconversion.convertStringToBoolean(request.getParameter("aButtonsNextPrevious"));
	HashMap<String, Object> queryCreteria = new HashMap<String, Object>();
	queryCreteria.put("EmployeeId", employeeId);
	int actionFieldCount = dataconversion.getPersistance(buttonUpdateCaption) + 
						   dataconversion.getPersistance(buttonDeleteCaption) + 
						   dataconversion.getPersistance(buttonOtherCaption);
	int totalFieldCount = fieldHeadings.size() + actionFieldCount - 1;
	int totalRecordCount = framework.getRowCount(queryCreteria, dataGridPageID);
	boolean isActionFieldEnable = (actionFieldCount> 0? true: false);
	List<List> dataGridRowData = framework.getFieldDataForPage(dataGridPageID, queryCreteria, nextRowNumber, numberOfRecordsPerPage);
	int numberOfRecordsFetched = dataGridRowData.size();
	%>
	<h5><u>Employee Lieu Leave History Details</u></h5>
	<table class="datagridstyle">
		<tr class="grid-heding-row-style">
			<%
			for (int i=0; i < fieldHeadings.size(); i++) {
				if (isActionFieldEnable && actionFieldCount > 1 && i == (fieldHeadings.size() - 1)) {
				%>
					<th colspan="<%=actionFieldCount %>" class="grid-heding-cell-style"><%=fieldHeadings.get(i) %></th>									
				<%
				} else {
			%>
					<th class="grid-heding-cell-style"><%=fieldHeadings.get(i) %></th>
			<%
				}
			}
			%>
		</tr>
	<%
	  if (dataGridRowData.size() > 0) {
		for (int i=0; i < dataGridRowData.size(); i++) {
			List rowData = dataGridRowData.get(i);
	%>	
			<tr <% if (i%2 == 0) { %> class="data-row-even-style" <% } else { %> class="data-row-odd-style" <% } %> >
	<% 
			for (int j=0; j < dataFieldCoulmnCount; j++) {
	%>
				<td class="data-row-cell-style"><%=rowData.get(j) %></td>
	<%
			}

			if (isActionFieldEnable) {
	%>
					<% 
					// Button One
						if (dataconversion.isNotNull(buttonUpdateCaption)) {
					%>
					<td>
						<form name="RowAction" method="post" action="/<%=configProps.getProperty("SYSTEM_ROOT_URL") %>/DataGridComponentUpdateActionServlet" >
							<input type="hidden" name="FieldCount" value="<%=rowData.size() %>" />
							<input type="hidden" name="DataGridPageID" value="<%=dataGridPageID %>" />
					<%
						for (int j=0; j < rowData.size(); j++) {
					%>
							<input type="hidden" name="Field<%=j %>" value="<%=rowData.get(j) %>" />
					<%
						}
					%>
							<input class="buttonstyle" name="submit" type="submit" value="<%=buttonUpdateCaption %>" />
						</form>
					</td>
					<%		
						}

					// Button Two
						if (dataconversion.isNotNull(buttonDeleteCaption)) {
					%>
					<td>
						<form name="RowAction" method="post" action="/<%=configProps.getProperty("SYSTEM_ROOT_URL") %>/DataGridComponentDeleteActionServlet" >
							<input type="hidden" name="FieldCount" value="<%=rowData.size() %>" />
							<input type="hidden" name="DataGridPageID" value="<%=dataGridPageID %>" />
					<%
						for (int j=0; j < rowData.size(); j++) {
					%>
							<input type="hidden" name="Field<%=j %>" value="<%=rowData.get(j) %>" />
					<%
						}
					%>
							<input class="buttonstyle" name="submit" type="submit" value="<%=buttonDeleteCaption %>" <% if (rowData.get(2).equals(configProps.getProperty("CANCEL")) ||
									rowData.get(2).equals(configProps.getProperty("REJECTED"))) { %> disabled="disabled" <% } %>/>
						</form>
					</td>
					<%		
						}

					// Button Three
						if (dataconversion.isNotNull(buttonOtherCaption)) {
					%>
					<td>
						<form name="RowAction" method="post" action="/<%=configProps.getProperty("SYSTEM_ROOT_URL") %>/DataGridComponentOtherActionServlet" >
							<input type="hidden" name="FieldCount" value="<%=rowData.size() %>" />
							<input type="hidden" name="DataGridPageID" value="<%=dataGridPageID %>" />
					<%
						for (int j=0; j < rowData.size(); j++) {
					%>
							<input type="hidden" name="Field<%=j %>" value="<%=rowData.get(j) %>" />
					<%
						}
					%>
							<input class="buttonstyle" name="submit" type="submit" value="<%=buttonOtherCaption %>" />
						</form>
					</td>
					<%		
						}
					%>
	<%
			}
	%>
			</tr>
	<%
		}
	  } else {
	%>
		<tr class="grid-no_data-message-row-style">
			<td colspan="<%=totalFieldCount %>">
				<%=configProps.getProperty("SYSTEM_DATAGRID_NO_DATA_MESSAGE_TEXT") %>
			</td>
		</tr>
	<%
	  }
	%>
	</table>
	<br />
	<br />
	<%
	if (buttonsNextPrevious && totalRecordCount > numberOfRecordsPerPage) {
		int forwardRowNumber = nextRowNumber + numberOfRecordsPerPage;
		int backwordRowNumber = nextRowNumber - numberOfRecordsPerPage;
		int lastDisplayRecordNumber = 0;
		if ((totalRecordCount - nextRowNumber) <= numberOfRecordsPerPage) {
			lastDisplayRecordNumber = nextRowNumber + numberOfRecordsFetched;
		} else {
			lastDisplayRecordNumber = nextRowNumber + numberOfRecordsPerPage;
		}
	%>
		<table class="paginationtable">
			<tr class="pagination-button-bar">
				<td class="cell-style-01">
				  <form name="paginationBar" method="post" action="/<%=configProps.getProperty("SYSTEM_ROOT_URL") %>/DataGridComponentNextPreviousServlet">
					<input type="submit" name="Previous" value="Previous" class="nextprevbuttonstyle" <% if (nextRowNumber == 0) { %> disabled="disabled" <% } %>/>
					<input type="hidden" name="PreviousRowNumber" value="<%=backwordRowNumber %>">
					<input type="hidden" name="DataGridPageID" value="<%=dataGridPageID %>">
				  </form>
				</td>
				<td class="cell-style-03">
					Displaying <%=nextRowNumber+1 %> to <%=lastDisplayRecordNumber %> of <%=totalRecordCount %> items
				</td>
				<td class="cell-style-02">
				<form name="paginationBar" method="post" action="/<%=configProps.getProperty("SYSTEM_ROOT_URL") %>/DataGridComponentNextPreviousServlet">
					<input type="submit" name="Next" value="Next" class="nextprevbuttonstyle" <% if ((totalRecordCount - nextRowNumber) <= numberOfRecordsPerPage) { %> disabled="disabled" <% } %> />
					<input type="hidden" name="NextRowNumber" value="<%=forwardRowNumber %>">
					<input type="hidden" name="DataGridPageID" value="<%=dataGridPageID %>">
				</form>
				</td>
			</tr>
		</table>
<%
	}
} catch (FrontierVisibleException e) {
%>
	<table class="datagriderrortabletyle">
		<tr class="exception-message-style">
			<td>System Configuration error..!!! Please contact system administrator... <%=e.getDetailsErrorMessage() %></td>
		</tr>
	</table>
<%
}
%>